const { defineConfig } = require('@vue/cli-service')
let contentPath = "/oss"
// 当前时间戳，用于清除浏览器缓存
let date = new Date()
let year = date.getFullYear()
let month = date.getMonth() + 1
let day = date.getDate()
let hours = date.getHours()
let minutes = date.getMinutes()
let seconds = date.getSeconds()
let minutesSeconds = date.getMilliseconds()
let timeStamp = year+'Y'+month+'M'+day+'D'+hours+'H'+minutes+'m'+seconds+'s'+minutesSeconds
console.log('编译时间=',timeStamp);

module.exports = defineConfig(() => {
  return {
    // 静态文件目录
    publicPath: contentPath,
    outputDir: "dist",
    assetsDir: "static",
    devServer: {
      // 路由跳转之后，进行页面刷新时，返回404的错误
      historyApiFallback: {
        index: contentPath+"/index.html",
      },
      // 元素大小改变时更新了DOM结构，从而导致重新计算元素大小的循环触发,ResizeObserver loop completed with undelivered notifications
      client: {
        overlay: false,
      },
      port: 998,
      open: false,
      proxy: {
        "/oss-api": {
          target: "http://localhost:10010", // 本地环境
          changeOrigin: true,
          pathRewrite: { "^/oss-api": "/" }, // 测试环境
        },
      },
    },
    // vue-cli构建项目时, 控制台警告 Feature flag __VUE_PROD_HYDRATION_MISMATCH_DETAILS__ is not explicitly defined.
    chainWebpack: (config) => {
      config.plugin("define").tap((definitions) => {
        Object.assign(definitions[0], {
          __VUE_OPTIONS_API__: "true",
          __VUE_PROD_DEVTOOLS__: "false",
          __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: "false",
        });
        return definitions;
      });
    },
    // 打包时生成的js文件名添加时间戳，防止浏览器缓存问题
    configureWebpack:{
      output:{
        filename: `js/[name].js?v=${timeStamp}`,
        chunkFilename: `js/[name].chunk.js?v=${timeStamp}`
      }
    },
    // 打包时生成的css文件名添加时间戳，防止浏览器缓存问题
    css:{
      extract:{
        filename: `css/[name].${timeStamp}.css`,
        chunkFilename: `css/[name].${timeStamp}.css`
      }
    }
  };
});
